/*************************************************
 * Copyright (C), 2009-2020, Kong.
 * File name: global.h
 * Author: Kong       Version: 1.0       Date: 2009.6.6
 * Description:  //声明公共变量
 * Others:
 * Function List:  // 主要函数列表，每条记录应包括函数名及功能简要说明
 * History:
*************************************************/

#ifndef __GLOBAL_H
#define __GLOBAL_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>

//#define CONFIG_FILE "~/.kh-shell"
#define CONFIG_FILE_NAME ".kh-shell"

//#define CMD_LEN 256
#define MAX_JOB 256	//最大子进程数
#define MAX_LINE 256	//命令行缓冲大小
#define MAX_ARGC 256	//最大参数个数
#define NAME_LEN 256	//最大目录、文件名长度

extern int err_no;

//extern int flags;
extern char *reserved_words[];
enum reserved_words_index{
	INPUT_REDIRECTION_INDEX,
	OUTPUT_REDIRECTION_INDEX,
	EXIT_INDEX,
	RUN_BCKGRND_INDEX,
	RUN_FRNTGRND_INDEX,
	CHGPRMT_INDEX,
	CD_INDEX
};

enum environ_argv_index{
	USER_INDEX	= 1, 	//登录用户名
	PWD_INDEX,		//当前工作目录
	HOME,			//home目录
	PROMPT_INDEX, 		//提示符
	LAST_INDEX, 		//最后一个元素
};
extern char *environ_argv[LAST_INDEX];

//#define F_IFMASK		0x0000003F
#define F_IFCD			0x00000080
#define F_IFCHGPRMT		0x00000040
#define F_IFFRNTGRND		0x00000020
#define F_IFBCKGRND		0x00000010
#define F_IFEXIT		0x00000008
#define F_IFOPRE		0x00000004
#define F_IFIPRE		0x00000002
#define F_IFCMD			0x00000001

#define SET_CD(flags) \
	flags = ((flags) | F_IFCD)
#define IS_CD(flags) \
	(((flags) & F_IFCD) == F_IFCD)
#define SET_CMD(flags) \
	flags = ((flags) | F_IFCMD)
#define IS_CMD(flags) \
	(((flags) & F_IFCMD) == F_IFCMD)
#define SET_INPUT_REDIREC(flags) \
	flags = ((flags) | F_IFIPRE)
#define IS_INPUT_REDIREC(flags) \
	(((flags) & F_IFIPRE) == F_IFIPRE)
#define SET_OUTPUT_REDIREC(flags) \
	flags = ((flags) | F_IFOPRE)
#define IS_OUTPUT_REDIREC(flags) \
	(((flags) & F_IFOPRE) == F_IFOPRE)
#define SET_EXIT(flags) \
	flags = ((flags) | F_IFEXIT)
#define IS_EXIT(flags) \
	(((flags) & F_IFEXIT) == F_IFEXIT)
#define SET_RUN_BCKGRND(flags) \
	flags = ((flags) | F_IFBCKGRND)
#define IS_RUN_BCKGRND(flags) \
	(((flags) & F_IFBCKGRND) == F_IFBCKGRND)
#define SET_RUN_FRNTGRND(flags) \
	flags = ((flags) | F_IFFRNTGRND)
#define IS_RUN_FRNTGRND(flags) \
	(((flags) & F_IFFRNTGRND) == F_IFFRNTGRND)
#define SET_CHGPRMT(flags) \
	flags = ((flags) | F_IFCHGPRMT)
#define IS_CHGPRMT(flags) \
	(((flags) & F_IFCHGPRMT) == F_IFCHGPRMT)
	
#endif
